import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, applyMiddleware } from 'redux';
import { createLogger } from 'redux-logger';
import thunkMiddleware from 'redux-thunk';
import storeReducer from './reducers';
import { Provider } from 'react-redux';
import './index.css';
import RouterDom from './routes';
import * as serviceWorker from './serviceWorker';
import { fetchPosts } from './actions';

const loggerMiddleware = createLogger();

const store = createStore(
    storeReducer, 
    applyMiddleware(
        thunkMiddleware,
        loggerMiddleware
));

store.dispatch(fetchPosts('get datas')).then(() => console.log( store.getState() ))

ReactDOM.render(
    <Provider store={store}>
        <RouterDom />
    </Provider>,
    document.getElementById('root')
);

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: http://bit.ly/CRA-PWA
serviceWorker.unregister();
